package com.example.administrator.myapplication;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;

import com.example.administrator.myapplication.adapter.SelectAdapter;
import com.example.administrator.myapplication.base.BaseActivity;
import com.example.administrator.myapplication.media.Sound;

public class SelectActivity extends BaseActivity {
    //选关界面
    private Gallery mGallery ;
    private int mImageId;//当前显示的图片ID
    private int mLevel; //难度数值
    private final static int[] IMGIDS = new int[]{R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,R.drawable.b5};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        //找到Gallery
        mGallery = (Gallery) findViewById(R.id.select_gallery);
        SelectAdapter adapter = new SelectAdapter(this,IMGIDS);
        mGallery.setAdapter(adapter);
        //设置每个条目点击事件
        mGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mImageId = IMGIDS[position];
                AlertDialog.Builder builder = new AlertDialog.Builder(SelectActivity.this);
                builder.setIcon(R.drawable.about).setTitle("请选择游戏难度");
                builder.setPositiveButton("简单",onClickListener);
                builder.setNeutralButton("一般", onClickListener);
                builder.setNegativeButton("困难", onClickListener);
                builder.show();
            }
        });
    }
    private DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Sound.play(1);
            switch (which){
                case DialogInterface.BUTTON_POSITIVE:
                    mLevel = 3;
                    break;
                case DialogInterface.BUTTON_NEUTRAL:
                    mLevel = 4;
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    mLevel = 5;
                    break;
            }
            //窗口跳转
            Bundle bundle = new Bundle();
            bundle.putInt("level",mLevel);
            bundle.putInt("imageId",mImageId);

            startActivity(StartGameActivity.class, bundle);

        }
    };
}
